package com.snap.awesomeserial.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.snap.awesomeserial.MoleApplication;

public class SpUtils {

    private final static String SP_SET_CONFIG = "config";

    private SharedPreferences sp;
    private static SpUtils instance;

    private SpUtils() {
        sp = MoleApplication.get().getSharedPreferences(SP_SET_CONFIG, Context.MODE_PRIVATE);
    }

    public static SpUtils get() {
        if (instance == null) {
            instance = new SpUtils();
        }
        return instance;
    }

    public boolean putInt(String key, int value) {
        return sp.edit().putInt(key, value).commit();
    }

    public int getInt(String key, int defValue) {
        return sp.getInt(key, defValue);
    }

    public boolean putFloat(String key, float value) {
        return sp.edit().putFloat(key, value).commit();
    }

    public float getFloat(String key, float defValue) {
        return sp.getFloat(key, defValue);
    }

    public boolean putString(String key, String value) {
        return sp.edit().putString(key, value).commit();
    }

    public String getString(String key, String defValue) {
        return sp.getString(key, defValue);
    }

    public float getFloat(String key) {
        return getFloat(key, 0f);
    }

    public boolean clear(String key) {
        return sp.edit().remove(key).commit();
    }

    public boolean clearAll() {
        return sp.edit().clear().commit();
    }
}
